package com.etrans.web.gps.timer;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;

import com.etrans.web.gps.business.system.service.CommonService;

public class BaseInfo {
	
    @Autowired
    private CommonService commonService;
	
	public void getBaseInfo() {
		System.out.println(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
		long start = System.currentTimeMillis();
		try {
			//加载所有平台
			List<HashMap<String, Object>> plats = commonService.queryAllPlatform(null);
			Map<Integer, String> platMap = new HashMap<>();
			for (HashMap<String, Object> plat : plats) {
				platMap.put(Integer.valueOf(plat.get("id")+""), plat.get("text")+"");
			}
			if (platMap != null && !platMap.isEmpty()) {
				LocalCache.platMap.clear();
				LocalCache.platMap.putAll(platMap);
			}
			//加载所有业户
			List<HashMap<String, Object>> ents = commonService.queryEnterprise(null);
			Map<Integer, String> entMap = new HashMap<>();
			for (HashMap<String, Object> ent : ents) {
				entMap.put(Integer.valueOf(ent.get("id")+""), ent.get("text")+"");
			}
			if (entMap != null && !entMap.isEmpty()) {
				LocalCache.entMap.clear();
				LocalCache.entMap.putAll(entMap);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		long end = System.currentTimeMillis();
		System.out.println("=============获取基础信息，用时：" + (end-start)/1000 + "." + (end-start)%1000 + "秒==============");
	}
}
